<?php
class Manage extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->database ();
	}
	// 用户管理
	function user() {
		$province = $this->Mprovince->getAll ();
		$data ['province'] = $province;
		$this->load->view ( 'usermanage', $data );
	}
	function loadUser() {
		$realname = $this->input->post ( 'realname' );
		$provinceid = $this->input->post ( 'provinceid' );
		$cityid = $this->input->post ( 'cityid' );
		$sex = $this->input->post ( 'sex' );
		$minAge = $this->input->post ( 'minAge' );
		$maxAge = $this->input->post ( 'maxAge' );
		$idstatus = $this->input->post ( 'idstatus' );
		$status = $this->input->post ( 'status' );
		$no = 1;
		$query = $this->Muser->loadUser ( $realname, $provinceid, $cityid, $sex, $minAge, $maxAge, $idstatus, $status );
		
		
		
		$result = "";
		
		foreach ( $query as $row ) {
			
			$result .= "<tr>
					<td><input type='checkbox' value='" . $row->id . "' /></td>
					<td>$no</td>
					<td>$row->username</td>
					<td>$row->realname</td>
					<td>$row->sex</td>
					<td>$row->age</td>
					<td>$row->provincename - $row->cityname</td>
					<td>$row->regtime</td>
					<td>$row->idcardtypename</td>
					<td>$row->idstatusname</td>
					<td>" . $this->getModelType ( $row->modeltype ) . "</td>
					<td>$row->statusname</td>
					<td>
					<a href='javascript:void(0)' style='color:blue' onclick='auditIdCardManage(" . $row->id . ")'>审核认证</a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='javascript:void(0)' style='color:blue' onclick='modify(" . $row->id . ")'>编辑</a>
					&nbsp;&nbsp;&nbsp;&nbsp;		
					<a href='javascript:void(0)' style='color:blue' onclick='del(" . $row->id . ")'>删除</a>
					&nbsp;&nbsp;&nbsp;&nbsp;		
					<a href='javascript:void(0)' style='color:blue' onclick='mamageAlbum(" . $row->id . ")'>相册管理</a>
					</td>
					</tr>";
			$no ++;
		}
		echo $result;
	}
	function getModelType($modeltype) {
		if (! isset ( $modeltype ))
			return "";
		
		$name = $this->Mdic->getModelType ( $modeltype );
		return $name;
	}
	
	//
	function newuser() {
		$province = $this->Mprovince->getAll ();
		$data ['province'] = $province;

        $data['icon'] = $this->Muserimg->getUserIcon();

		$this->load->view ( 'newuser', $data );
	}

    /**
     * 图标
     * @return mixed
     */
    function getIcon()
    {
       $icon = $this->Muserimg->getUserImg();
    }

	function getUserInfoById() {
		$id = $this->input->post ( 'id' );
		$arr['user'] = $this->Muser->getById ( $id );

        $arr['icon'] = $this->Musericon->getUserIcon($id);
		echo json_encode ( $arr );
	}
	function modifyUser() {
		$arr = array ();
		$arr ["ReturnCode"] = 0;
		$sex = $this->input->post ( 'sex' );
		$realname = $this->input->post ( 'realname' );
		$birthday = $this->input->post ( 'birthday' );
		$provinceid = $this->input->post ( 'provinceid' );
		$cityid = $this->input->post ( 'cityid' );
		$jgprovinceid = $this->input->post ( 'jgprovinceid' );
		$jgcityid = $this->input->post ( 'jgcityid' );
		$phone = $this->input->post ( 'phone' );
		$email = $this->input->post ( 'email' );
		$qq = $this->input->post ( 'qq' );
		$id = $this->input->post ( 'id' );
		$isvalid = $this->input->post ( 'isvalid' );
		$weibo = $this->input->post ( 'weibo' );
		$pwd = $this->input->post ( 'pwd' );
        $iconId = $this->input->post('iconId');
		$this->Muser->modifyUser ( $id, $realname, $birthday, $provinceid, $cityid, $jgprovinceid, $jgcityid, $phone, $email, $pwd, $qq, $sex, $isvalid ,$iconId);
		
		$this->Mweibo->delWeibo ( 1, $id );
		$this->Mweibo->saveWeibo ( $id, 1, $weibo );
		
		$arr ['ReturnCode'] = 1;
		echo json_encode ( $arr );
	}
	function delUser() {
		$ids = $this->input->post ( 'uid' );
		$ids = trim ( $ids, "," );
		$ids = "(" . $ids . ")";
		$this->Muser->delUser ( $ids );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	// 认证管理
	function card() {
		$province = $this->Mprovince->getAll ();
		$data ['province'] = $province;
		$this->load->view ( 'idcardmanage', $data );
	}
	function auditCard() {
		$this->load->view ( 'card' );
	}
	// 审核认证
	function modifyIdCard() {
		$id = $this->input->post ( 'id' );
		$idcardstatus = $this->input->post ( 'idcardstatus' );
		$idcardremark = $this->input->post ( 'idcardremark' );
		$this->Muser->modifyIdCard ( $id, $idcardremark, $idcardstatus );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	// 系统设置
	function systemset() {
		$this->load->view ( 'systemset' );
	}
	// 相册管理
	function album() {
		$this->load->view ( 'album' );
	}
	function loadAlbums() {
		$arr = array ();
		$uid = $this->input->post ( 'uid' );
		$query = $this->Malbum->loadAlbums ( $uid );
		$result = "";
		$names = "";
		foreach ( $query as $row ) {
			$result .= "<li><img src='images/vip_img.jpg' />
			<div class='xc_sl'>共";
			$result .= $this->Malbumdetail->getCount ( $row->id, 1 );
			$result .= "张</div> <span>" . $row->name . "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='showdetail($uid," . $row->id . ")'>[ 明细 ]</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='delalbum(" . $row->id . ")'>[ 删除 ]</a>
					</span></li>";
			
			$names .= "<option value='" . $row->id . "'>" . $row->name . "</option>";
		}
		$arr ["album"] = $result;
		$arr ["albumNames"] = $names;
		echo json_encode ( $arr );
	}
	function loadAlbumDetails() {
		$arr = array ();
		$id = $this->input->post ( 'id' );
		$query = $this->Malbumdetail->loadAlbumDetails ( $id );
		
		$result = "";
		$names = "";
		foreach ( $query as $row ) {
			$result .= "<li><img src='".base_url()."uploads/".$row->url."' />
			<br/><br/><a href='javascript:void(0)' style='color:blue' onclick='delalbumdetail(" . $row->id . ")'>[ 删除 ]</a>
					</span></li>";
		}
		$arr ["album"] = $result;
		echo json_encode ( $arr );
	}
	function delAblums() {
		$arr = array ();
		$id = $this->input->post ( 'id' );
		$this->Malbum->delAblums ( $id );
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function delAblumDetails() {
		$arr = array ();
		$id = $this->input->post ( 'id' );
		$this->Malbumdetail->delAblumDetails ( $id );
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function albumdetail() {
		$this->load->view ( 'albumdetail' );
	}
	function deleteByAlbumid() {
		$arr = array ();
		$id = $this->input->post ( 'id' );
		$this->Malbumdetail->deleteByAlbumid ( $id );
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function albumtrash() {
		$this->load->view ( 'albumtrash' );
	}
	function loadAlbumTrash() {
		$arr = array ();
		$uid = $this->input->post ( 'uid' );
		$query = $this->Malbum->loadAlbumsDeleted ( $uid );
		$result = "";
		
		foreach ( $query as $row ) {
			$result .= "<li><img src='images/vip_img.jpg' />
			<div class='xc_sl'>共";
			$result .= $this->Malbumdetail->getCount ( $row->id, 0 );
			$result .= "张</div> <span>" . $row->name . "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='restoreTrash(1," . $row->id . ")'>[ 恢复 ]</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='delAlbumTrash(1," . $row->id . ")'>[ 彻底删除 ]</a>
					</span></li>";
		}
		$queryDetail = $this->Malbumdetail->loadAlbumDetailsDeleted ( $uid );
		foreach ( $queryDetail as $row ) {
			$result .= "<li><img src='" . $row->url . "' />
			<div class='xc_sl'>";
			$result .= "</div> <span> &nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='restoreTrash(2," . $row->id . ")'>[ 恢复 ]</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onclick='delAlbumTrash(2," . $row->id . ")'>[ 彻底删除 ]</a>
					</span></li>";
		}
		
		$arr ["album"] = $result;
		echo json_encode ( $arr );
	}
	function restoreAblum() {
		$id = $this->input->post ( 'id' );
		$this->Malbum->restoreAblum ( $id );
		$arr = array ();
		
		$arr ["ReturnCode"] = $id;
		echo json_encode ( $arr );
	}
	function restoreAblumDetail() {
		$id = $this->input->post ( 'id' );
		$this->Malbumdetail->restoreAblumDetail ( $id );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function deleteAlbumDeep() {
		$id = $this->input->post ( 'id' );
		$this->Malbum->deleteAlbumDeep ( $id );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function deleteAblumDetailDeep() {
		$id = $this->input->post ( 'id' );
		$this->Malbumdetail->deleteAlbumDetailDeep ( $id );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	// 用户组管理
	function usergroup() {
		$this->load->view ( 'usergroup' );
	}
	function loadUserGroup() {
		$name = $this->input->post ( 'name' );
		
		$query = $this->Musergroup->loadUserGroup ( $name );
		$result = "";
		foreach ( $query as $row ) {
			$result .= "<tr>
					<td><input type='checkbox' value='" . $row->id . "' /></td>					
					<td>$row->name</td>					
					<td>					
					<a href='javascript:void(0)' style='color:blue' onclick='modifyUserGroup(" . $row->id . ")'>编辑</a>
					&nbsp;&nbsp;&nbsp;&nbsp;		
					<a href='javascript:void(0)' style='color:blue' onclick='delUserGroup(" . $row->id . ")'>删除</a>					
					</td>
					</tr>";
		}
		echo $result;
	}
	function delUserGroup() {
		$id = $this->input->post ( 'id' );
		$id = trim ( $id, "," );
		$id = "($id)";
		$this->Musergroup->delUserGroup ( $id );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function newUserGroup() {
		$this->load->view ( 'newgroup' );
	}
	function checkExistsUserGroupName() {
		$id = $this->input->post ( 'id' );
		$name = $this->input->post ( 'name' );
		$exists = false;
		if ($id == 0) {
			$exists = $this->Musergroup->checkExistsName ( $name );
		} else {
			$exists = $this->Musergroup->checkExistsNameForUpdate ( $id, $name );
		}
		$arr = array ();
		if ($exists)
			$arr ["ReturnCode"] = 0;
		else
			$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function getUserGroupById() {
		$id = $this->input->post ( 'id' );
		$arr = $this->Musergroup->getUserGroupById ( $id );
		echo json_encode ( $arr );
	}
	function addUserGroup() {
		$id = $this->input->post ( 'id' );
		$name = $this->input->post ( 'name' );
		if ($id == 0) {
			$this->Musergroup->addUserGroup ( $name );
		} else {
			$this->Musergroup->updateUserGroup ( $id, $name );
		}
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function selGroup() {
		$group = $this->Musergroup->getUserGroupAll ();
		$data ['group'] = $group;
		$this->load->view ( 'selGroup', $data );
	}
	function modifyUserGroup() {
		$gid = $this->input->post ( 'gid' );
		$ids = $this->input->post ( 'ids' );
		$ids = trim ( $ids, "," );
		$ids = "($ids)";
		$this->Muser->modifyUserGroup ( $ids, $gid );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	// 站内信管理
	function loadSms() {
		$name = $this->input->post ( 'name' );
		
		$query = $this->Msms->loadSms ();
		$result = "";
		foreach ( $query as $row ) {
			$result .= "<tr>
					<td><input type='checkbox' value='" . $row->id . "' /></td>
							<td>$row->id</td>
							<td>$row->title</td>";
			
			$result .= "<td>" . $this->getGroupName ( $row->groupidstr ) . "</td>
							<td>$row->createtime</td>
							<td>$row->remark</td>
							<td>
							<a href='javascript:void(0)' style='color:blue' onclick='modifySms(" . $row->id . ")'>查看</a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='javascript:void(0)' style='color:blue' onclick='delSms(" . $row->id . ")'>删除</a>
							</td>
					</tr>";
		}
		echo $result;
	}
	function delSms() {
		$ids = $this->input->post ( 'ids' );
		
		$ids = trim ( $ids, "," );
		$ids = "($ids)";
		if ($ids != "") {
			$this->Msms->delSms ( $ids );
		}
		$arr = array (
				"ReturnCode" => 1 
		);
		echo json_encode ( $arr );
	}
	function getGroupName($groupid) {
		$arr = explode ( "/", $groupid );
		$result = "";
		foreach ( $arr as $value ) {
			if ($value != "") {
				$temp = $this->Musergroup->getUserGroupNameById ( $value );
				$result .= $temp . "&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		}
		$result = trim ( $result, " " );
		return $result;
	}
	// 站内信
	function smsmanage() {
		$this->load->view ( 'smsmanage' );
	}
	function newsms() {
		$group = $this->Musergroup->getUserGroupAll ();
		$data ['group'] = $group;
		$this->load->view ( 'newsms', $data );
	}
	function addSms() {
		$title = $this->input->post ( 'title' );
		$content = $this->input->post ( 'content' );
		$groupid = $this->input->post ( 'groupidstr' );
		$groupid = trim ( $groupid, "/" );
		$groupid = "/$groupid/";
		$remark = $this->input->post ( 'remark' );
		$username = $this->input->post ( 'username' );
		$this->Msms->addSms ( $title, $content, $groupid, $remark, $username );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function getSmsById() {
		$id = $this->input->post ( 'id' );
		$arr = $this->Msms->getSmsById ( $id );
		echo json_encode ( $arr );
	}
	
	// 管理员管理
	function adminmanage() {
		$this->load->view ( 'adminmanage' );
	}
	function loadAdmin() {
		$query = $this->Madmin->loadAdmin ();
		$result = "";
		foreach ( $query as $row ) {
			$result .= "<tr>
					<td><input type='checkbox' value='" . $row->id . "' /></td>
							<td>$row->id</td>
							<td>$row->username</td>							
							<td>$row->isvalidname</td>
							<td>$row->lastlogintime</td>
							<td>$row->lastloginip</td>	
							<td>
			<a href='javascript:void(0)' style='color:blue' onclick='modifyAdmin(" . $row->id . ")'>编辑</a>
			&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='javascript:void(0)' style='color:blue' onclick='delAdmin(" . $row->id . ")'>删除</a>
							";
			
			if ($row->isdefault == "1") {
				$result .= "&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='javascript:void(0)' style='color:blue' onclick='setAdminDefault(" . $row->id . ")'>设置为非默认管理员</a>";
			} else {
				$result .= "&nbsp;&nbsp;&nbsp;&nbsp;
						<a href='javascript:void(0)' style='color:blue' onclick='setAdminDefault(" . $row->id . ")'>设置为默认管理员</a>";
			}
			$result .= "</td>
					</tr>";
		}
		echo $result;
	}
	function newAdmin() {
		$this->load->view ( 'newadmin' );
	}
	function checkExistsAdmin() {
		$id = $this->input->post ( 'id' );
		$username = $this->input->post ( 'username' );
		$exists = false;
		if ($id != 0) {
			$exists = $this->Madmin->checkExistsAdminForUpdate ( $id, $username );
		} else {
			$exists = $this->Madmin->checkExistsAdmin ( $username );
		}
		
		$arr = array ();
		if ($exists)
			$arr ["ReturnCode"] = 0;
		else
			$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function addAdmin() {
		$username = $this->input->post ( 'username' );
		$pwd = $this->input->post ( 'pwd' );
		$isvalid = $this->input->post ( 'isvalid' );
		$id = $this->input->post ( 'id' );
		if ($id > 0) { // 修改
			$this->Madmin->modifyAdmin ( $id, $pwd, $isvalid );
		} else { // 添加
			$this->Madmin->addAdmin ( $username, $pwd, $isvalid );
		}
	}
	function delAdmin() {
		$ids = $this->input->post ( 'ids' );
		$ids = trim ( "$ids", "," );
		$ids = "($ids)";
		$this->Madmin->delAdmin ( $ids );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function setDefault() {
		$ids = $this->input->post ( 'ids' );
		$ids = trim ( "$ids", "," );
		$ids = "($ids)";
		$this->Madmin->setDefault ( $ids );
		$arr = array ();
		$arr ["ReturnCode"] = 1;
		echo json_encode ( $arr );
	}
	function getAdminById() {
		$id = $this->input->post ( 'id' );
		$arr = $this->Madmin->getAdminById ( $id );
		echo json_encode ( $arr );
	}
	// 站点管理
	function sitemanage() {
		$this->load->view ( 'sitemanage' );
	}
	function getSite() {
		$arr = $this->Msite->getSite ();
		echo json_encode ( $arr );
	}
	function setSite() {
		$name = $this->input->post ( 'name' );
		$title = $this->input->post ( 'title' );
		$keywords = $this->input->post ( 'keywords' );
		$sitedesc = $this->input->post ( 'sitedesc' );
		$headlogo = $this->input->post ( 'headlogo' );
		$bottomlogo = $this->input->post ( 'bottomlogo' );
		$beian = $this->input->post ( 'beian' );
		$stacode = $this->input->post ( 'stacode' );
		$status = $this->input->post ( 'status' );
		$bottominfo = $this->input->post ( 'bottominfo' );
		$reginfo = $this->input->post ( 'reginfo' );
		$anticheatguide = $this->input->post ( 'anticheatguide' );
		$this->Msite->setSite ( $name, $title, $keywords, $sitedesc, $headlogo, $bottomlogo, $beian, $stacode, $status, $bottominfo, $reginfo, $anticheatguide );
		$arr = array (
				"ReturnCode" => 1 
		);
		echo json_encode ( $arr );
	}
	function setHeadLogoUrl() {
		$a = $this->Msite->getSite();
		$this->delImg($a["headlogourl"]);
		$headlogourl = $this->input->post ( 'headlogourl' );
		$this->Msite->setHeadLogoUrl ( $headlogourl );
		$arr = array (
				"ReturnCode" => 1 
		);
		echo json_encode ( $arr );
	}
	function setBottomLogoUrl() {
		$a = $this->Msite->getSite();
		$this->delImg($a["bottomlogourl"]);
		$bottomLogoUrl = $this->input->post ( 'bottomLogoUrl' );
		$this->Msite->setBottomLogoUrl ( $bottomLogoUrl );
		$arr = array (
				"ReturnCode" => 1 
		);
		echo json_encode ( $arr );
	}
	//
	function userimgmanage(){
		$this->load->view('userimgmanage');
	}
    function getUserImg(){
        $arr = $this->Muserimg-> getUserImg();
        echo json_encode($arr);
    }
    function saveUserImg(){
        $a = $this->Muserimg->getUserImg();
        $type = $this->input->post('type');
        $url = $this->input->post('url');



        if($type=="1")
            $this->delImg($a["shurl"]);
        else if($type=="2")
            $this->delImg($a["mturl"]);
        else if($type=="3")
            $this->delImg($a["syurl"]);
        else if($type=="4")
            $this->delImg($a["hyurl"]);
        else if($type=="5")
            $this->delImg($a["rzurl"]);


        $this->Muserimg->saveUserImg($type,$url);

        $arr = array (
            "ReturnCode" => 1
        );
        echo json_encode ( $arr );
    }
    function setUserImg(){
        $sh = $this->input->post('sh');
        $shisvalid = $this->input->post('shisvalid');
        $mt = $this->input->post('mt');
        $mtisvalid = $this->input->post('mtisvalid');
        $sy = $this->input->post('sy');
        $syisvalid = $this->input->post('syisvalid');
        $hy = $this->input->post('hy');
        $hyisvalid = $this->input->post('hyisvalid');
        $rz = $this->input->post('rz');
        $rzisvalid = $this->input->post('rzisvalid');
        $this->Muserimg->setUserImg($sh,$shisvalid,$mt,$mtisvalid,$sy,$syisvalid,$hy,$hyisvalid,$rz,$rzisvalid);
        $arr = array (
            "ReturnCode" => 1
        );
        echo json_encode ( $arr );
    }
	
	//图片配置
	function imgconfig(){
		$this->load->view('imgconfig');
	}
	function getImgConfig(){
		$arr = $this->Mimgconfig->getImgConfig();
		echo json_encode($arr);
	}
	function setImgConfig(){
		$imgtext = $this->input->post('imgtext');
		$capacity = $this->input->post('capacity');
		$location = $this->input->post('location');
		$limitsize = $this->input->post('limitsize');
		$imgtype = $this->input->post('imgtype');
		$isvalid = $this->input->post('isvalid');
		//echo "$imgtext-$capacity-$location-$limitsize-$imgtype-$isvalid";
		//exit;
		$this->Mimgconfig-> setImgConfig($imgtext, $capacity, $location, $limitsize, $imgtype, $isvalid);
		$arr = array(
			"ReturnCode"=>1
		);
		echo json_encode($arr);
	}
	function saveImgConfig(){
		$a = $this->Mimgconfig->getImgConfig();
		$this->delImg($a["imgurl"]);
		$url = $this->input->post('imgurl');
		$this->Mimgconfig->saveImgConfig($url);
	}

	function login(){
		$arr = array ();
		$username = $_POST ["login_user"];
		$pwd = $_POST ["login_pwd"];
		
		$arr ["ReturnCode"] = "0";
		if (empty ( $username )) {
			$arr ["Msg"] = "用户名不能为空";
			echo json_encode ( $arr );
			exit ();
		}
		
		if (empty ( $pwd )) {
			$arr ["Msg"] = "密码不能为空";
			echo json_encode ( $arr );
			exit ();
		}
		
		$arr ["Msg"] = "用户名或密码错误";
		
		$query = $this->Madmin->login($username,$pwd);
		
		$url = "Location:http://" . $_SERVER ['HTTP_HOST'];
		foreach ( $query as $row ) {
			$this->session->set_userdata ( 'id', $row->id );
			$this->session->set_userdata ( 'username', $row->username );
			$this->session->set_userdata ( 'isadmin', '1' );
			
			$arr["ReturnCode"] = 1;
			//$url = "Location:http://" . $_SERVER ['HTTP_HOST'];
			//header ( $url );
			//exit;
			$ip = $this->input->ip_address();
			$this->Madmin->updateLoginIP($username,$ip);
		}
		echo json_encode($arr);
		
		//$url = $url . "?err='not exists'";
		//header ( $url );
		//exit;
	}
	function logout(){
		$this->session->unset_userdata ( 'id' );
		$this->session->unset_userdata ( 'username' );
		$this->session->unset_userdata ( 'isadmin' );
		
		$url = "Location:" . base_url().'admin.php';
		header ( $url );
		exit;
	}
	
	
	
	function uploadImg($imgName) {
		$arr = array ();
		$arr ["ReturnCode"] = 0;
		// $picname = $_FILES ['mypic'] ['name'];
		// $picsize = $_FILES ['mypic'] ['size'];
		$picname = $_FILES [$imgName] ['name'];
		$picsize = $_FILES [$imgName] ['size'];
		if ($picname != "") {
			if ($picsize > 1024000 * 3) {
				$arr ["Msg"] = '图片大小不能超过3M';
				echo json_encode ( $arr );
				exit ();
			}
			$type = strstr ( $picname, '.' );
			if ($type != ".gif" && $type != ".jpg" && $type != ".png" && $type != ".jpeg") {
				$arr ["Msg"] = '图片格式不对！';
				echo json_encode ( $arr );
				exit ();
			}
			$rand = rand ( 100, 999 );
			$pics = "a" . "_" . date ( "YmdHis" ) . $rand . $type;
			// 上传路径
			$pic_path = "./uploadimg/";
			if (is_dir ( $pic_path ) == false) {
				mkdir ( $pic_path, 0777 );
			}
			$pic_path .= $pics;
			// move_uploaded_file ( $_FILES ['mypic'] ['tmp_name'], $pic_path );
			move_uploaded_file ( $_FILES [$imgName] ['tmp_name'], $pic_path );
		}
		$size = round ( $picsize / 1024, 2 );
		$arr = array (
				'ReturnCode' => 1,
				'name' => $picname,
				'src' => "uploadimg/" . $pics,
				'size' => $size 
		);
		echo json_encode ( $arr );
	}
	function delImg($imgname) {
		try {
			if (! empty ( $imgname )) {
				if (file_exists ( $imgname ))
					unlink ( $imgname );
			}
		} catch ( Exception $e ) {
		}
	}

    /**
     * 报名微访谈
     */
    function baominInteview()
    {
        $numPerPage = $this->input->post('numPerPage') >= 1 ? $this->input->post('numPerPage') : 20;

        $data['data'] = $this->Mapplyinterview->getApply('',$numPerPage);

        $this->load->view ('baominInteview',$data);
    }

    function loadInteview()
    {
        $realname = $this->input->post('realname');

        $query = $this->Mapplyinterview->getApply($realname,20);

        $result = "";
        foreach ( $query['data'] as $row ) {
            $result .= "<tr>
					<td><input type='checkbox' value='" . $row['id'] . "' /></td>
							<td>".$row['id']."</td>
							<td>".$row['realname']."</td>
							<td>".$row['weixin']."</td>
							<td>
					<a href='javascript:void(0)' style='color:blue' onclick='delSelectMultiInterview(" . $row['id'] . ")'>删除</a></td>
							";
            $result .= "</tr>";
        }
        echo $result;
    }

    function deleteInteview()
    {
        $id = trim($this->input->post('ids'),',');

        if(empty($id)){
            $data['statusCode'] = 2;
            $data['msg'] = '参数错误';
            echo json_encode($data);
            exit;
        }

        $this->Mapplyinterview->deleteApply($id);

        $data['statusCode'] = 1;
        $data['msg'] = '删除成功';
        echo json_encode($data);

    }




}
?>
